package com.example.supermarket.mapper;

import com.example.supermarket.pojo.Business;
import com.example.supermarket.pojo.Item;
import com.example.supermarket.pojo.Order;
import com.example.supermarket.pojo.Shop;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BusinessMapper {

    @Select("select * from business where user_id=#{userId}")
    Business findByUserId(Integer userId);

    @Insert("insert into shop(business_id,shop_name,shop_img) values (#{businessId},#{shopName},#{shopImg})")
    void createShop(Shop shop);

    @Insert("insert into item(business_id,item_name,isListed,item_img,price) " +
            "values (#{businessId},#{itemName},0,#{itemImg},#{price})")
    void createShopItem(Item item);

    @Insert("insert into shopitem(shop_id,item_id) values (#{shopId},#{itemId})")
    void listItem(Integer shopId, Integer itemId);

    @Delete("delete from shopitem where shop_id=#{shopId} and item_id=#{itemId}")
    void delistItem(Integer shopId, Integer itemId);

    @Select("select * from shopitem where item_id=#{itemId}")
    List<Item> findByItemId(Integer itemId);

    @Update("update item set isListed=1 where item_id=#{itemId}")
    void list(Integer itemId);

    @Update("update item set isListed=0 where item_id=#{itemId}")
    void delist(Integer itemId);

    @Select("select * from `order` where shop_id=#{shopId}")
    List<Order> getOrderByShopId(Integer shopId);

    @Update("update `order` set status=2 where order_id=#{orderId}")
    void confirmOrder(Integer orderId);

    @Update("update `order` set status=3 where order_id=#{orderId}")
    void cancelOrder(Integer orderId);
}
